/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frontera;

import Control.CrudTarea;
import Control.VerificarEstado;
import Entidad.Tarea;
import java.awt.Color;
import java.text.DateFormat;

/**
 *
 * @author Stiv
 */
public class VentanaInf extends javax.swing.JFrame {
    
    
    Color customColor = new Color(192,230,43);
    int id;
    DateFormat dfDefault = DateFormat.getDateInstance();
    
    
    public VentanaInf() {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    public VentanaInf(int id) {
        
        initComponents();
        ListaEstados.setVisible(false);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.id = id;
        recibirID();
    }
    
    

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        NombreTF = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        idL = new javax.swing.JLabel();
        idTF = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        fechaL = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        estadoL = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        clienteL = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        tipoL = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        ownerL = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        descripcionTA = new javax.swing.JTextArea();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel3 = new javax.swing.JLabel();
        cedulaL = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        direccionL = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        telefonoL = new javax.swing.JLabel();
        cerrarBT = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        barraProgreso = new javax.swing.JProgressBar();
        jLabel9 = new javax.swing.JLabel();
        estadoBT = new javax.swing.JButton();
        ListaEstados = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(660, 383));

        NombreTF.setBackground(new java.awt.Color(204, 51, 0));
        NombreTF.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        NombreTF.setForeground(new java.awt.Color(255, 255, 255));
        NombreTF.setText("Nombre Tarea");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("ID");

        idL.setText("jLabel2");

        idTF.setBackground(new java.awt.Color(204, 51, 0));
        idTF.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        idTF.setForeground(new java.awt.Color(204, 204, 204));
        idTF.setText("3");
        idTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                idTFActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Fecha límite");

        fechaL.setText("jLabel3");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Estado");

        estadoL.setText("jLabel5");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Cliente");

        clienteL.setText("jLabel7");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("Tipo");

        tipoL.setText("jLabel9");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("Asignado a");

        ownerL.setText("jLabel11");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Descripción");

        descripcionTA.setColumns(20);
        descripcionTA.setRows(5);
        jScrollPane1.setViewportView(descripcionTA);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Cedula");

        cedulaL.setText("jLabel5");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("Direccion");

        direccionL.setText("jLabel9");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel11.setText("Telefono");

        telefonoL.setText("jLabel13");

        cerrarBT.setText("Cerrar");
        cerrarBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cerrarBTActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Progreso");

        barraProgreso.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        barraProgreso.setForeground(new java.awt.Color(204, 255, 0));
        barraProgreso.setStringPainted(true);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("Cambiar Estado");

        estadoBT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/imagenes/Bandera.png"))); // NOI18N
        estadoBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                estadoBTActionPerformed(evt);
            }
        });

        ListaEstados.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Revisada", "Ejecutada", "Bloqueada", "Terminada" }));
        ListaEstados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ListaEstadosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel8)
                            .addComponent(jLabel10))
                        .addGap(38, 38, 38))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tipoL)
                    .addComponent(ownerL)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(idL)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fechaL)
                            .addComponent(estadoL))))
                .addGap(166, 166, 166)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel6)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel5)
                                .addComponent(jLabel11)))))
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(direccionL)
                    .addComponent(clienteL)
                    .addComponent(cedulaL)
                    .addComponent(telefonoL)
                    .addComponent(barraProgreso, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(230, 230, 230))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(idTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NombreTF, javax.swing.GroupLayout.PREFERRED_SIZE, 575, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 388, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(estadoBT, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(ListaEstados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(cerrarBT)))))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NombreTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(idTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(idL)
                            .addComponent(clienteL)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2)
                                    .addComponent(fechaL))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel4)
                                    .addComponent(estadoL))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel8)
                                    .addComponent(tipoL))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel10)
                                    .addComponent(ownerL)
                                    .addComponent(jLabel5)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel3)
                                    .addComponent(cedulaL))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel7)
                                    .addComponent(direccionL))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel11)
                                    .addComponent(telefonoL))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(barraProgreso, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                        .addGap(89, 89, 89)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ListaEstados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cerrarBT))
                        .addComponent(estadoBT, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(79, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void idTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_idTFActionPerformed

    private void cerrarBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cerrarBTActionPerformed
        this.dispose ();
        this.setVisible (false);
        
    }//GEN-LAST:event_cerrarBTActionPerformed

    
    
    private void estadoBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_estadoBTActionPerformed
        ListaEstados.setVisible(true);
        
           
    }//GEN-LAST:event_estadoBTActionPerformed

    private void ListaEstadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ListaEstadosActionPerformed
        try{
             String nuevoEstado = (String)ListaEstados.getSelectedItem();
             int progreso = VerificarEstado.Progreso(nuevoEstado);
             CrudTarea.ModificarEstado(id, nuevoEstado, progreso);
             estadoL.setText(nuevoEstado);   
             if(nuevoEstado == "Bloqueada") barraProgreso.setForeground(Color.red);
             else barraProgreso.setForeground(customColor);
             barraProgreso.setValue(progreso);
             PanelTareas.dtmtareas.setValueAt(nuevoEstado, id-1, 2);
            
        }
        catch(Exception e){
            System.out.print("exception");
            e.printStackTrace();
        }
    }//GEN-LAST:event_ListaEstadosActionPerformed

    /**
     * aram args the command line arguments
     
    public static void main(String args[]) {
        
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VentanaInf().setVisible(true);
            }
        });
    }
    */
    
    
    
    public void recibirID(){
        for(Tarea u: CrudTarea.bringAll()){
                if(u.getID() == id){
                    idTF.setText("00" + String.valueOf(u.getID()));
                    NombreTF.setText(u.getNombre());
                    idL.setText(String.valueOf(u.getID()));
                    fechaL.setText(dfDefault.format(u.getFecha_fin().getTime()));
                    estadoL.setText(u.getEstado());
                    clienteL.setText(u.getCompra().getCliente().getNombre());
                    tipoL.setText(u.getTipo());
                    ownerL.setText(u.getEmpleado());
                    descripcionTA.setText(u.getDescripcion());
                    cedulaL.setText(String.valueOf(u.getCompra().getCliente().getID()));
                    direccionL.setText(u.getCompra().getCliente().getDireccion());
                    telefonoL.setText(String.valueOf(u.getCompra().getCliente().getTelefono()));
                    barraProgreso.setValue(u.getProgreso());
                    
                    
                    
                }
                
                }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox ListaEstados;
    private javax.swing.JTextField NombreTF;
    private javax.swing.JProgressBar barraProgreso;
    private javax.swing.JLabel cedulaL;
    private javax.swing.JButton cerrarBT;
    private javax.swing.JLabel clienteL;
    private javax.swing.JTextArea descripcionTA;
    private javax.swing.JLabel direccionL;
    private javax.swing.JButton estadoBT;
    private javax.swing.JLabel estadoL;
    private javax.swing.JLabel fechaL;
    private javax.swing.JLabel idL;
    private javax.swing.JTextField idTF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel ownerL;
    private javax.swing.JLabel telefonoL;
    private javax.swing.JLabel tipoL;
    // End of variables declaration//GEN-END:variables
}
